package com.bestsoft.web.controller.baseinfo;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bestsoft.common.annotation.Log;
import com.bestsoft.common.core.controller.BaseController;
import com.bestsoft.common.core.domain.AjaxResult;
import com.bestsoft.common.enums.BusinessType;
import com.bestsoft.baseinfo.domain.BaseInfoGoods;
import com.bestsoft.baseinfo.service.IBaseInfoGoodsService;
import com.bestsoft.common.utils.poi.ExcelUtil;
import com.bestsoft.common.core.page.TableDataInfo;

/**
 * 商品资料Controller
 * 
 * @author1 王识宇
 * @date 2023-09-19
 */
@RestController
@RequestMapping("/domain/goods")
public class BaseInfoGoodsController extends BaseController
{
    @Autowired
    private IBaseInfoGoodsService baseInfoGoodsDocService;

    /**
     * 查询商品资料列表
     */
    @PreAuthorize("@ss.hasPermi('domain:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(BaseInfoGoods baseInfoGoodsDoc)
    {
        startPage();
        List<BaseInfoGoods> list = baseInfoGoodsDocService.selectBaseInfoGoodsDocList(baseInfoGoodsDoc);
        return getDataTable(list);
    }

    /**
     * 导出商品资料列表
     */
    @PreAuthorize("@ss.hasPermi('domain:goods:export')")
    @Log(title = "商品资料", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BaseInfoGoods baseInfoGoodsDoc)
    {
        List<BaseInfoGoods> list = baseInfoGoodsDocService.selectBaseInfoGoodsDocList(baseInfoGoodsDoc);
        ExcelUtil<BaseInfoGoods> util = new ExcelUtil<BaseInfoGoods>(BaseInfoGoods.class);
        util.exportExcel(response, list, "商品资料数据");
    }

    /**
     * 获取商品资料详细信息
     */
    @PreAuthorize("@ss.hasPermi('domain:goods:query')")
    @GetMapping(value = "/{goodid}")
    public AjaxResult getInfo(@PathVariable("goodid") Long goodid)
    {
        return success(baseInfoGoodsDocService.selectBaseInfoGoodsDocByGoodid(goodid));
    }

    /**
     * 新增商品资料
     */
    @PreAuthorize("@ss.hasPermi('domain:goods:add')")
    @Log(title = "商品资料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BaseInfoGoods baseInfoGoodsDoc)
    {
        return toAjax(baseInfoGoodsDocService.insertBaseInfoGoodsDoc(baseInfoGoodsDoc));
    }

    /**
     * 修改商品资料
     */
    @PreAuthorize("@ss.hasPermi('domain:goods:edit')")
    @Log(title = "商品资料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BaseInfoGoods baseInfoGoodsDoc)
    {
        return toAjax(baseInfoGoodsDocService.updateBaseInfoGoodsDoc(baseInfoGoodsDoc));
    }

    /**
     * 删除商品资料
     */
    @PreAuthorize("@ss.hasPermi('domain:goods:remove')")
    @Log(title = "商品资料", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodids}")
    public AjaxResult remove(@PathVariable Long[] goodids)
    {
        return toAjax(baseInfoGoodsDocService.deleteBaseInfoGoodsDocByGoodids(goodids));
    }
}
